package com.fpt.dao;

import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import junit.framework.TestCase;

import org.junit.Test;

import com.fpt.common.valueobjects.PupilVO;

public class PupilDaoTest extends TestCase{

	// Test truong hop khi nhap gia tri ten hop le
	@Test
	public void testSearchPupilByName_InputValidName_SearchSuccess() {
		PupilDao pupilDao = new PupilDao();
		List<PupilVO> listPupilVO ;
		listPupilVO = pupilDao.searchPupilByName("luan");
		PupilVO object = listPupilVO.get(0);
		if((object.getId() == 1) && (object.getName().equals("luan"))){
			assertTrue(true);
		}
	}

	// Test truong hop khi nhap gia tri ten la chuoi rong
	@Test
	public void testSearchPupilByName_PupilNameIsNull_ReturnNullValue() {
		PupilDao pupilDao = new PupilDao();
		List<PupilVO> listPupilVO = pupilDao.searchPupilByName("");
		if(listPupilVO == null){
			assertTrue(true);
		}
	}
	
	
	// Test truong hop khi nhap gia tri ten co chua so
	@Test
	public void testSearchPupilByName_PupilNameIsNumber_ReturnNullValue() {
		PupilDao pupilDao = new PupilDao();
		List<PupilVO> listPupilVO = pupilDao.searchPupilByName("12345");
		if(listPupilVO == null){
			assertTrue(true);
		}
	}
	
	
	
	// Test truong hop khi nhap gia tri ten qua ngan
	@Test
	public void testSearchPupilByName_PupilNameIsShorted_ReturnNullValue() {
		PupilDao pupilDao = new PupilDao();
		List<PupilVO> listPupilVO = pupilDao.searchPupilByName("a");
		if(listPupilVO == null){
			assertTrue(true);
		}
	}
	
	
	
	//Test truong hop khi nhap vao doi tuong lop nhap vao hop le
	@Test
	public void testAddPupil_InputPupilIsValid_ReturnSuccess() {
		Date date;
		PupilVO pupilVO;
		try {
			DateFormat fm = new SimpleDateFormat("mm-dd-yyyy");
			date = fm.parse("01-01-1989");
			java.sql.Date sqlDate = new java.sql.Date(date.getTime());
			pupilVO = new PupilVO("Nguyen Van Binh", sqlDate , "Ha Noi", "Nam");
			PupilDao pupilDao = new PupilDao();
			if(pupilDao.addPupil(pupilVO));
				assertTrue(true);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	
	//Test truong hop khi nhap vao doi tuong lop nhap vao la NULL
	@Test
	public void testAddPupil_InputPupilIsNull_ReturnNull() {
		PupilVO pupilVO = null;
		PupilDao pupilDao = new PupilDao();
		if(pupilDao.addPupil(pupilVO) == false);
		assertTrue(true);
		
	}

}
